from utils import file
import os
import sys

config_file_path = "/config"
stores_path = "/stores"


def init_config_stores():
    if not file.is_dir(config_file_path):
        raise Exception("请先上传配置文件目录")
    if not file.is_dir(stores_path):
        os.mkdir(stores_path)
        config_files = os.listdir(config_file_path)
        for config_f in config_files:
            src = f"{config_file_path}/{config_f}"
            target = f"{stores_path}/{config_f}"
            file.copy_file(src, target)
            os.remove(src)
        print("初始化/stores完毕,请刷新文件目录")
    else:
        # copy new configs
        pass
    try:
        os.rmdir(config_file_path)
    except Exception as e:
        sys.print_excetion(e)


### 持久化配置文件
init_config_stores()
